package com.alibaba.controller;

import com.alibaba.model.param.LoginRequest;
import com.alibaba.service.UserService;
import com.alibaba.utils.Result;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 *
 * @author ZhouYaDong
 * @date 2025/9/25
 * @description
 */
@RequestMapping("/user")
@RestController
public class UserController {

    @Resource
    private UserService userService;

    // 获取登录验证码
    @GetMapping("/code")
    public Result<String> getCode(@RequestParam("username") String username) {
        userService.sendLoginCode(username);
        return Result.success("验证码发送成功");
    }

    // 登录
    @PostMapping("/login")
    public Result<String> login(@RequestBody @Validated LoginRequest request) {
        String result = userService.login(request);
        return Result.success(result);
    }

}
